package com.it.work3;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity /* implements View.OnClickListener */ {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });


        // 1. 匿名内部类
        Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 在这里处理按钮的点击事件
                Toast.makeText(MainActivity.this, "Button clicked (匿名内部类)", Toast.LENGTH_SHORT).show();
            }
        });


        // 2. 接口实现
        // Button button = findViewById(R.id.button1);
        // // 设置按钮点击事件的监听器
        // button.setOnClickListener(this);
    }

    // @Override
    // public void onClick(View v) {
    //     // 处理按钮点击事件
    //     if (v.getId() == R.id.button1) {
    //         // 显示Toast消息
    //         Toast.makeText(this, "Button clicked (接口实现)", Toast.LENGTH_SHORT).show();
    //     }
    // }


    // 3. 在布局中设置Button属性实现
    // public void onLoginClick(View view) {
    //     // 执行登录操作
    //     Toast.makeText(this, "Button clicked (在布局中设置Button属性实现)", Toast.LENGTH_SHORT).show();
    // }
}